<?php

class GalleryAlbum {
	private $ID;
	private $AlbumName;
	private $AlbumDisplayName;
	private $Comment = "";
	private $Images = array();
	private $Visibility;

	private $Controller;

	function __construct($album_name, $GalleryController){
		$this->Controller = $GalleryController;

		$MySQL = $this->Controller->UseApps["mysql"];

		$Sql = $MySQL->generateSelectQuery($MySQL->getPrefix()."lightbox_albums", array("album_name" => $album_name));

		$QueryAlbum = $MySQL->query($Sql);
		
		if(mysql_num_rows($QueryAlbum) <= 0){
			return;
		}
		
		$Fetch = mysql_fetch_assoc($QueryAlbum);
		
		$this->ID = $Fetch["id"];
		$this->AlbumName = $Fetch["album_name"];
		$this->AlbumDisplayName = $Fetch["album_display_name"];
		$this->Comment = (!empty($Fetch["album_comment"])) ? $Fetch["album_comment"] : "";
		$this->Visibility = ($Fetch["album_visibility"] == "true") ? true : false; 
	}

	function getID(){
		return $this->ID;
	}

	function getAlbumName(){
		return $this->AlbumName;
	}

	function getDisplayName(){
		return $this->AlbumDisplayName;
	}

	function getImages(){
		if($this->Images === false){
			return false;
		}
		
		if(count($this->Images) <= 0){
			$MySQL = $this->Controller->UseApps["mysql"];

			$Sql = $MySQL->generateSelectQuery($MySQL->getPrefix()."lightbox_images", array("album_id" => $this->ID), "id DESC");
	
			$QueryImages = $MySQL->query($Sql);			

			if(mysql_num_rows($QueryImages) <= 0){
				$this->Images = false;
				return false;
			}
			
			while($image = mysql_fetch_assoc($QueryImages)){
				$this->Images[] = new GalleryImage($image["id"], $this->Controller);
			}
			
		}
	
		return $this->Images;
	}

	function getComment(){
		return $this->Comment;
	}

	function getPath(){
		$path = dirname(__FILE__)."/../content/lbgallery/".$this->AlbumName;
	}

	function getURLPath(){
		$SiteURL = Core::$FMSConfig->getValue("environment", "url");
		$FullURL = $SiteURL."lightboxgallery/album/".$this->AlbumName."/";
		
		return $FullURL;
	}
	
	function getVisibility(){
		return ($this-> Visibility == true) ? true : false;
	}
}

?>